<template>
  <div class="dungeon-data-container">
    <div class="dungeon-header">
      <h1>副本数据</h1>
      <div class="search-box">
        <input 
          type="text" 
          v-model="searchQuery" 
          placeholder="搜索副本..."
          @input="handleSearch"
        >
        <button class="search-btn">
          <i class="fas fa-search"></i>
        </button>
      </div>
    </div>

    <div class="filter-bar">
      <div class="filter-group">
        <label>难度等级：</label>
        <div class="difficulty-tags">
          <button 
            v-for="difficulty in difficulties" 
            :key="difficulty"
            class="difficulty-tag"
            :class="{ active: selectedDifficulty === difficulty }"
            @click="selectDifficulty(difficulty)"
          >
            {{ difficulty }}
          </button>
        </div>
      </div>
      <div class="filter-group">
        <label>副本类型：</label>
        <div class="type-tags">
          <button 
            v-for="type in types" 
            :key="type"
            class="type-tag"
            :class="{ active: selectedType === type }"
            @click="selectType(type)"
          >
            {{ type }}
          </button>
        </div>
      </div>
    </div>

    <div class="dungeons-grid">
      <div 
        v-for="dungeon in filteredDungeons" 
        :key="dungeon.id"
        class="dungeon-card"
        @click="selectDungeon(dungeon)"
      >
        <div class="dungeon-image">
          <img :src="dungeon.image" :alt="dungeon.name">
          <div class="dungeon-difficulty" :class="dungeon.difficulty.toLowerCase()">
            {{ dungeon.difficulty }}
          </div>
        </div>
        <div class="dungeon-info">
          <h3>{{ dungeon.name }}</h3>
          <div class="dungeon-meta">
            <span class="type">{{ dungeon.type }}</span>
            <span class="level">推荐等级: {{ dungeon.recommendedLevel }}</span>
          </div>
          <div class="dungeon-stats">
            <div class="stat">
              <span class="label">通关率</span>
              <span class="value">{{ dungeon.clearRate }}%</span>
            </div>
            <div class="stat">
              <span class="label">平均时间</span>
              <span class="value">{{ dungeon.avgTime }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div v-if="selectedDungeon" class="dungeon-detail-modal">
      <div class="modal-content">
        <button class="close-btn" @click="selectedDungeon = null">
          <i class="fas fa-times"></i>
        </button>
        
        <div class="detail-header">
          <div class="dungeon-banner">
            <img :src="selectedDungeon.image" :alt="selectedDungeon.name">
            <div class="dungeon-overlay">
              <h2>{{ selectedDungeon.name }}</h2>
              <div class="meta-info">
                <span class="difficulty" :class="selectedDungeon.difficulty.toLowerCase()">
                  {{ selectedDungeon.difficulty }}
                </span>
                <span class="type">{{ selectedDungeon.type }}</span>
                <span class="level">推荐等级: {{ selectedDungeon.recommendedLevel }}</span>
              </div>
            </div>
          </div>
        </div>

        <div class="detail-content">
          <div class="content-section">
            <h3>副本信息</h3>
            <div class="info-grid">
              <div class="info-item">
                <span class="label">通关率</span>
                <span class="value">{{ selectedDungeon.clearRate }}%</span>
              </div>
              <div class="info-item">
                <span class="label">平均时间</span>
                <span class="value">{{ selectedDungeon.avgTime }}</span>
              </div>
              <div class="info-item">
                <span class="label">参与人数</span>
                <span class="value">{{ selectedDungeon.participants }}</span>
              </div>
              <div class="info-item">
                <span class="label">重置时间</span>
                <span class="value">{{ selectedDungeon.resetTime }}</span>
              </div>
            </div>
          </div>

          <div class="content-section">
            <h3>推荐阵容</h3>
            <div class="teams-list">
              <div v-for="team in selectedDungeon.recommendedTeams" :key="team.id" class="team-card">
                <div class="team-characters">
                  <div v-for="character in team.characters" :key="character.id" class="team-character">
                    <img :src="character.avatar" :alt="character.name">
                    <span class="character-name">{{ character.name }}</span>
                  </div>
                </div>
                <div class="team-stats">
                  <div class="stat">
                    <span class="label">胜率</span>
                    <span class="value">{{ team.winRate }}%</span>
                  </div>
                  <div class="stat">
                    <span class="label">平均时间</span>
                    <span class="value">{{ team.avgTime }}</span>
                  </div>
                </div>
              </div>
            </div>
          </div>

          <div class="content-section">
            <h3>掉落物品</h3>
            <div class="drops-list">
              <div v-for="drop in selectedDungeon.drops" :key="drop.id" class="drop-card">
                <img :src="drop.icon" :alt="drop.name" class="drop-icon">
                <div class="drop-info">
                  <span class="drop-name">{{ drop.name }}</span>
                  <span class="drop-rate">掉落率: {{ drop.rate }}%</span>
                </div>
              </div>
            </div>
          </div>

          <div class="content-section">
            <h3>通关攻略</h3>
            <div class="strategy-content" v-html="selectedDungeon.strategy"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'

const searchQuery = ref('')
const selectedDifficulty = ref('')
const selectedType = ref('')
const selectedDungeon = ref(null)

const difficulties = ['简单', '普通', '困难', '噩梦']
const types = ['剧情', '挑战', '活动', '世界BOSS']

// 模拟副本数据
const dungeons = ref([
  {
    id: 1,
    name: '元素试炼',
    image: '/dungeons/element-trial.jpg',
    difficulty: '困难',
    type: '挑战',
    recommendedLevel: 80,
    clearRate: 78.5,
    avgTime: '3分15秒',
    participants: 12500,
    resetTime: '每周一',
    recommendedTeams: [
      {
        id: 1,
        characters: [
          { id: 1, name: '伊莉雅', avatar: '/characters/elisa.jpg' },
          { id: 2, name: '艾莉丝', avatar: '/characters/alice.jpg' }
        ],
        winRate: 85.2,
        avgTime: '2分45秒'
      }
    ],
    drops: [
      {
        id: 1,
        name: '元素结晶',
        icon: '/materials/crystal.jpg',
        rate: 25.5
      }
    ],
    strategy: `
      <h4>副本机制</h4>
      <p>1. 每30秒会刷新一波小怪</p>
      <p>2. 击败所有小怪后会出现BOSS</p>
      <h4>推荐打法</h4>
      <p>1. 优先清理小怪，避免被包围</p>
      <p>2. BOSS出现后注意躲避技能</p>
    `
  }
])

const filteredDungeons = computed(() => {
  return dungeons.value.filter(dungeon => {
    const matchesSearch = dungeon.name.toLowerCase().includes(searchQuery.value.toLowerCase())
    const matchesDifficulty = !selectedDifficulty.value || dungeon.difficulty === selectedDifficulty.value
    const matchesType = !selectedType.value || dungeon.type === selectedType.value
    return matchesSearch && matchesDifficulty && matchesType
  })
})

const handleSearch = () => {
  // 实现搜索逻辑
}

const selectDifficulty = (difficulty: string) => {
  selectedDifficulty.value = selectedDifficulty.value === difficulty ? '' : difficulty
}

const selectType = (type: string) => {
  selectedType.value = selectedType.value === type ? '' : type
}

const selectDungeon = (dungeon: any) => {
  selectedDungeon.value = dungeon
}
</script>

<style scoped>
.dungeon-data-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

.dungeon-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.dungeon-header h1 {
  margin: 0;
  color: #2c3e50;
}

.search-box {
  display: flex;
  gap: 0.5rem;
}

.search-box input {
  width: 300px;
  padding: 0.8rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 1rem;
}

.search-btn {
  padding: 0.8rem;
  background-color: #42b983;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.filter-bar {
  background: #f5f5f5;
  padding: 1.5rem;
  border-radius: 8px;
  margin-bottom: 2rem;
}

.filter-group {
  margin-bottom: 1rem;
}

.filter-group:last-child {
  margin-bottom: 0;
}

.filter-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: #666;
}

.difficulty-tags,
.type-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.difficulty-tag,
.type-tag {
  padding: 0.5rem 1rem;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.difficulty-tag.active,
.type-tag.active {
  background: #42b983;
  color: white;
  border-color: #42b983;
}

.dungeons-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
}

.dungeon-card {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: transform 0.3s;
}

.dungeon-card:hover {
  transform: translateY(-4px);
}

.dungeon-image {
  position: relative;
  padding-top: 56.25%;
}

.dungeon-image img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dungeon-difficulty {
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  color: white;
  font-weight: 500;
}

.dungeon-difficulty.简单 {
  background: #42b983;
}

.dungeon-difficulty.普通 {
  background: #3498db;
}

.dungeon-difficulty.困难 {
  background: #e74c3c;
}

.dungeon-difficulty.噩梦 {
  background: #9b59b6;
}

.dungeon-info {
  padding: 1rem;
}

.dungeon-info h3 {
  margin: 0 0 0.5rem;
  color: #2c3e50;
}

.dungeon-meta {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.type,
.level {
  padding: 0.2rem 0.5rem;
  background: #f5f5f5;
  border-radius: 4px;
  font-size: 0.9rem;
  color: #666;
}

.dungeon-stats {
  display: flex;
  gap: 1rem;
}

.stat {
  flex: 1;
  text-align: center;
}

.stat .label {
  display: block;
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 0.2rem;
}

.stat .value {
  font-size: 1.1rem;
  font-weight: 500;
  color: #2c3e50;
}

.dungeon-detail-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  border-radius: 8px;
  width: 90%;
  max-width: 1000px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 2rem;
  position: relative;
}

.close-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #666;
  cursor: pointer;
}

.detail-header {
  margin-bottom: 2rem;
}

.dungeon-banner {
  position: relative;
  height: 300px;
  border-radius: 8px;
  overflow: hidden;
}

.dungeon-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dungeon-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 2rem;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
  color: white;
}

.dungeon-overlay h2 {
  margin: 0 0 1rem;
  font-size: 2rem;
}

.meta-info {
  display: flex;
  gap: 1rem;
}

.meta-info span {
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  font-size: 0.9rem;
}

.content-section {
  margin-bottom: 2rem;
}

.content-section h3 {
  margin: 0 0 1rem;
  color: #2c3e50;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #eee;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.info-item {
  display: flex;
  flex-direction: column;
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.info-item .label {
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 0.5rem;
}

.info-item .value {
  font-size: 1.2rem;
  font-weight: 500;
  color: #2c3e50;
}

.teams-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.team-card {
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.team-characters {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.team-character {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.team-character img {
  width: 64px;
  height: 64px;
  border-radius: 4px;
}

.character-name {
  font-size: 0.9rem;
  color: #2c3e50;
}

.team-stats {
  display: flex;
  gap: 1rem;
}

.drops-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.drop-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: #f5f5f5;
  border-radius: 4px;
}

.drop-icon {
  width: 48px;
  height: 48px;
  border-radius: 4px;
}

.drop-info {
  flex: 1;
}

.drop-name {
  display: block;
  font-weight: 500;
  color: #2c3e50;
}

.drop-rate {
  font-size: 0.9rem;
  color: #666;
}

.strategy-content {
  line-height: 1.6;
  color: #2c3e50;
}

.strategy-content h4 {
  margin: 1.5rem 0 1rem;
  color: #2c3e50;
}

.strategy-content p {
  margin: 0.5rem 0;
}
</style> 